
import { _decorator, Component, Node } from 'cc';
import { Car } from './Car';
const { ccclass, property } = _decorator;

@ccclass('CarManager')
export class CarManager extends Component {
    @property({
        type: Car
    })
    mainCar: Car | null = null;

    public resetCars(points: Node[]) {
        if (points.length <= 0) {
            console.warn("There's no points in this map!");
            return;
        }

        this._createMainCar(points[0]);
    }

    private _createMainCar(point: Node) {
        this.mainCar?.setEntery(point);
    }

    public controlMoving(isRunning = true) {
        if (isRunning){
            this.mainCar?.startRunning();
        } else {
            this.mainCar?.stopRunning();
        }
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.0/manual/en/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.0/manual/en/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.0/manual/en/scripting/life-cycle-callbacks.html
 */
